package models

import (
	"gorm.io/gorm"
)

// OrderItem 订单商品明细表
type OrderItem struct {
	ID         uint64         `gorm:"primaryKey;autoIncrement;comment:明细主键"`
	OrderID    uint64         `gorm:"type:bigint;not null;index:idx_order_id;comment:订单ID" json:"order_id"`     // 外键
	ProductID  uint64         `gorm:"type:bigint;not null;index:idx_product_id;comment:商品ID" json:"product_id"` // 外键
	Quantity   uint64         `gorm:"type:int;not null;comment:购买数量" json:"quantity"`
	Price      float64        `gorm:"type:decimal(10,2);not null;comment:成交单价（元）" json:"price"`
	TotalPrice float64        `gorm:"type:decimal(10,2);not null;comment:小计（元）" json:"total_price"`
	CreatedAt  JsonTime       `gorm:"type:DATETIME;precision:0;index:idx_created_at;comment:创建时间" json:"created_at"`
	UpdatedAt  JsonTime       `gorm:"type:timestamp;comment:更新时间" json:"updated_at"`
	DeletedAt  gorm.DeletedAt `gorm:"type:DATETIME;precision:0;index;comment:删除时间" json:"-"`
}

// TableName 设置表名
func (OrderItem) TableName() string {
	return "order_items"
}
